﻿using System.Threading;
namespace com.fukefu
{
    public class MultiThread
    {
        int sleep = 0;
        public void Begin(int threadCount, ThreadStart th)
        {
            Thread[] thread = new Thread[threadCount];
            for (int i = 0; i < threadCount; i++)
            {
                thread[i] = new Thread(th);
                thread[i].IsBackground = true;
                thread[i].Name = "线程" + (i + 1).ToString();
                thread[i].Start();
                Thread.Sleep(sleep);
            }
            bool flag = true;
            while (flag)
            {
                flag = false;
                Thread.Sleep(200);
                for (int i = 0; i < threadCount; i++)
                {
                    if (thread[i].ThreadState != ThreadState.Stopped)
                    {
                        flag = true;
                        break;
                    }
                }
            }
            return;
        }
        public void SetSleepTime(int i)
        {
            sleep = i;
        }
    }
}
